__author__ = 'zoulida'

import pandas as pd
import akshare as ak

industry_names = ak.stock_board_industry_name_ths().loc[:, 'name']  # series类型
# industry_names = ['中药', '证券']
# 获取同花顺行业板块成交额
def get_amount(lists):
    result = pd.DataFrame()
    for name in lists:
        try:
            tmp = ak.stock_board_industry_index_ths(symbol=name).loc[:, ['日期', '成交额']].rename(columns={'成交额': name})
            tmp['日期'] = tmp['日期'].astype(str)
            tmp[name] = tmp[name].astype(float)
            tmp = tmp.set_index('日期').loc['2021-01-01':'2021-09-09']
            result = result.join(tmp, how='outer')
        except:
            print(tmp[name])
            continue
    return result
# 获取板块池中行业的成交额
industry_amount = get_amount(industry_names)
print(industry_amount)